<template>
  <view
    class="full-loading"
    :style="{
      background: background,
      height: fullLoading ? '100%' : '0px',
      opacity: fullLoading ? 1 : 0,
    }"
    @tap.stop="stopFun"
    @touchmove.stop.prevent="stopFun"
  >
    <view class="content">
      <view class="image-view">
        <image
          class="loading-img"
          :src="loadingIcon"
          mode="widthFix"
          :style="{ width: size, height: size }"
        />
      </view>
      <view class="text" :style="{ fontSize: fontSize, color: textColor }">{{ text }}</view>
    </view>
  </view>
</template>

<script setup lang="ts">
  import { computed } from 'vue';

  import { propTypes } from '@/utils/propTypes';
  const loadingGif = 'https://hb-saas.obs.cn-south-1.myhuaweicloud.com/mall/saas/icon/loading.gif';

  /**
   * 全屏loading
   * 例子:
   *  <full-loading :fullLoading="isFullLoading"></full-loading>
   */

  const props = defineProps({
    fullLoading: propTypes.bool.def(false),
    logoUrl: propTypes.string.def(''),
    text: propTypes.string.def(''),
    size: propTypes.string.def('200rpx'),
    fontSize: propTypes.string.def('22rpx'),
    textColor: propTypes.string.def('#999'),
    background: propTypes.string.def('rgba(255,255,255,.6)'),
  });

  const stopFun = () => false;

  const loadingIcon = computed(() => props.logoUrl || loadingGif);
</script>

<style lang="scss" scoped>
  @keyframes fade {
    0% {
      opacity: 0.6;
    }
    25% {
      opacity: 1;
    }
    50% {
      opacity: 0.6;
    }
    75% {
      opacity: 1;
    }
    100% {
      opacity: 0.6;
    }
  }
  .full-loading {
    width: 100%;
    background: #ffffff;
    position: fixed;
    z-index: 998;
    top: 0;
    left: 0;
    bottom: 0;
    overflow: hidden;
  }
  .full-loading .content {
    width: 300rpx;
    height: auto;
    position: absolute;
    z-index: 100;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    animation: fade 3500ms infinite linear;
    opacity: 0.6;
    padding: 10rpx;
  }
  .full-loading .image-view {
    text-align: center;
    font-size: 0;
  }
  .full-loading .image-view .loading-img {
    width: 138rpx;
    height: 138rpx;
    border-radius: 138rpx;
  }
  .full-loading .text {
    line-height: 1.5em;
    font-size: 22rpx;
    margin-top: 6px;
    text-align: center;
  }
</style>
